package com.mywork.activity;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ciko.code.utils.LogUtils;
import com.ciko.code.utils.SystemBarTintManager;
import com.mywork.R;

/**
 * Created by sihailin on 15/12/23.
 */
public class FillOutWorkPlaneActivity extends Activity {

    private final String TAG = this.getClass().getSimpleName();

    protected LinearLayout ll_root;

    private int type;

    private EditText editCont;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        LogUtils.v(TAG, "onCreate()");
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.activity_plane_fill_out);

        ll_root = (LinearLayout) super.findViewById(R.id.ll_root);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setTranslucentStatus(true);
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintResource(R.color.nav_bg_root);
            SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
            ll_root.setPadding(0, config.getStatusBarHeight(), 0, 0);
        }

        type = getIntent().getIntExtra("TYPE",0);
        String title = getIntent().getStringExtra("title");
        String content = getIntent().getStringExtra("CONTENT");
        editCont = (EditText)findViewById(R.id.eidt_cont);
        if(type ==1)
            ((TextView)findViewById(R.id.tv_title)).setText("周末完成工作");
        else if(type ==2) {
            ((TextView) findViewById(R.id.tv_title)).setText(title);
            editCont.setHint("请填写" + title);
        }
        else if(type ==3) {
            ((TextView) findViewById(R.id.tv_title)).setText(title);
            editCont.setHint("请填写" + title);
        }
        else if(type ==4) {
            ((TextView) findViewById(R.id.tv_title)).setText("需协调与帮助");
            editCont.setHint("请填写需协调与帮助事项");
        }
        else if(type ==5) {
            ((TextView) findViewById(R.id.tv_title)).setText("备注");
            editCont.setHint("请填写备注信息");
        }

        if(!TextUtils.isEmpty(content)){
            editCont.setText(content);
        }

        findViewById(R.id.llyt_btn_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(TextUtils.isEmpty(editCont.getText().toString())){
                    Toast.makeText(FillOutWorkPlaneActivity.this,"请输入内容",Toast.LENGTH_SHORT).show();
                }else{
                    Intent intent = new Intent();
                    intent.putExtra("cont",editCont.getText().toString());
                    setResult(RESULT_OK,intent);
                    finish();
                }
            }
        });

        findViewById(R.id.rect_imgNavBack).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @TargetApi(19)
    private void setTranslucentStatus(boolean on) {
        LogUtils.v(TAG, "setTranslucentStatus()");

        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }
}
